/*
 * Class:CEMTester
 * 
 * Description: Tester for the CEM package
 * 
 * Version:
 * 1.0 -Francois-Xavier Frenette - 20-11-2011
 * 		Adding the following tests:
 * 		testCalendarSingleton,testAgendaListEmpty, testCreateAgenda
 * 1.1 -Francois-Xavier Frenette - 11-12-2011
 * 		Adding the following tests:
 * 		testAgendaListManagement,testEventListManagement,testCreateEvent * 		
 * 
 * Copyright GPP - Genuine People Personality inc
 * 
 */
package calendarEventManager;

import java.sql.Timestamp;
import org.junit.Test;
import junit.framework.TestCase;

public class CEMTester extends TestCase {
	
	//**************************************************************
	// MODAL VARIABLES
	//**************************************************************
	private CEMCalendar m_oCalendar;
	private CEMAgenda m_oAgenda;
	private CEMEvent m_oEvent;
	
	//**************************************************************
	// Method: setUp
	// Description: Creates the objects on which the tests are
	//				performed
	//**************************************************************
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() {
		m_oCalendar = CEMCalendar.getInstance();
	}
	
	//**************************************************************
	// Method: setUp
	// Description: Creates the objects on which the tests are
	//				performed
	//**************************************************************
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() {
		m_oCalendar = null;
	}
	
	//**************************************************************
	// Method: testCalendarSingleton
	// Description: Tests if the calendar class is singleton
	//**************************************************************
	/**
	 * 
	 */
	@Test
	public void testCalendarSingleton() {
		CEMCalendar calendar2 = CEMCalendar.getInstance();
		assertEquals(m_oCalendar,calendar2);
	} // testCalendarSingleton()

	//**************************************************************
	// Method: testCreateAgenda
	// Description: Tests the creation of a new agenda
	//**************************************************************
	/**
	 * 
	 */
	@Test
	public void testCreateAgenda() {
		m_oAgenda = new CEMAgenda(0,"test agenda",1);
		assertNotNull(m_oAgenda);
		assertEquals(m_oAgenda.getAgendaId(), 0);
		assertEquals(m_oAgenda.getAgendaName(), "test agenda");
		assertEquals(m_oAgenda.getAgendaColour(), 1);
	} // testCreateAgenda()
	
	//**************************************************************
	// Method: testAgendaListManagement
	// Description: Tests the management of the agenda list
	//**************************************************************
	/**
	 * 
	 */
	@Test
	public void testAgendaListManagement() {
		// Test list is empty 
		assertTrue(m_oCalendar.getAgendaList().isEmpty());
		
		// Create new agenda
		m_oAgenda = new CEMAgenda(0,"test agenda",1);
		m_oCalendar.addAgenda(m_oAgenda);
		
		// Test add function
		assertTrue(!m_oCalendar.getAgendaList().isEmpty());
		
		// Test get function
		assertEquals(m_oAgenda, m_oCalendar.getAgenda(0));
		assertNull(m_oCalendar.getAgenda(1));
		
		// Test delete function
		assertEquals(m_oCalendar.deleteAgenda(0),CEMConstants.CEM_RETURN_CODE_OK);
		assertTrue(m_oCalendar.getAgendaList().isEmpty());	
		assertEquals(m_oCalendar.deleteAgenda(0),CEMConstants.CEM_RETURN_CODE_ERROR);
	} // testAgendaListManagement()
	
	//**************************************************************
	// Method: testCreateEvent
	// Description: Tests the creation of a new event
	//**************************************************************
	/**
	 * 
	 */
	@Test
	public void testCreateEvent() {
		m_oEvent = new CEMEvent(0, "new event", new Timestamp(0), new Timestamp(5), "this is a new event", 0);
		assertNotNull(m_oEvent);
		assertEquals(m_oEvent.getEventId(), 0);
		assertEquals(m_oEvent.getName(), "new event");
		assertEquals(m_oEvent.getStartingTime(), new Timestamp(0));
		assertEquals(m_oEvent.getEndingTime(), new Timestamp(5));
		assertEquals(m_oEvent.getDescription(),"this is a new event");
		assertEquals(m_oEvent.getAgendaId(),0);
	} // testCreateEvent()
	
	//**************************************************************
	// Method: testEventListManagement
	// Description: Tests the management of the events list
	//**************************************************************
	/**
	 * 
	 */
	@Test
	public void testEventListManagement() {
		m_oAgenda = new CEMAgenda(0,"test agenda",1);
		
		// Test list is empty 
		assertTrue(m_oAgenda.getEventsList().isEmpty());
		
		// Create new event
		m_oEvent = new CEMEvent(0, "new event", new Timestamp(0), new Timestamp(5), "this is a new event", 0);
		m_oAgenda.addEvent(m_oEvent);
		
		// Test add function
		assertTrue(!m_oAgenda.getEventsList().isEmpty());
		
		// Test get function
		assertEquals(m_oEvent, m_oAgenda.getEvent(0));
		assertNull(m_oAgenda.getEvent(1));
		
		// Test delete function
		assertEquals(m_oAgenda.deleteEvent(0),CEMConstants.CEM_RETURN_CODE_OK);
		assertTrue(m_oAgenda.getEventsList().isEmpty());	
		assertEquals(m_oAgenda.deleteEvent(0),CEMConstants.CEM_RETURN_CODE_ERROR);
	} // testEventListManagement()
	
} // Class CEMTester
